#include <iostream>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <cstdio>
using namespace std;
const int MAXN = 200;
struct Node
{
	int s, e, w;
};
vector<Node>mpt[MAXN];
int vis[MAXN];
int dis[MAXN], n;
void Spfa(int s)
{
	memset(vis, 0, sizeof(vis));
	memset(dis, 0x3f3f3f3f, sizeof(dis));
	dis[s] = 0;
	queue<int>v;
	v.push(s);
	while (!v.empty())
	{
		int t = v.front();
		v.pop();
		vis[t] = 0;
		for (int i = 0; i < mpt[t].size(); i++)
		{
			int temp = mpt[t][i].e;
			if (dis[temp] > dis[t] + mpt[t][i].w)
			{
				dis[temp] = dis[t] + mpt[t][i].w;
				if (vis[temp] == 0)
				{
					vis[temp] = 1;
					v.push(temp);
				}
			}
		}
	}
}
int main()
{
	int m;
	while (cin >> n >> m)
	{
		for (int i = 0; i < m; i++)
		{
			Node t;
			int x, y, w;
			cin >> x >> y >> w;
			t.s = x, t.e = y, t.w = w;
			mpt[t.s].push_back(t);
			t.e = x, t.s = y, t.w = w;
			mpt[t.s].push_back(t);
		}
		Spfa(1);
		for (int i = 1; i <= n; i++)
			cout << dis[i] << endl;
	}
	return 0;
}

